/**
 * 无尽模式武器选择界面
 */
class EndLessSelectWeaponUI extends BaseComp{
    private selectScroller:eui.Scroller;
    private selectList:eui.List;
    private weapon_group:eui.Group;
    private _listDataArr:eui.ArrayCollection;

    //列表是否展开了
    private isShow: boolean = true;
    //滚动区域消失位置的 x 坐标
    private posScrollerClose: number;
    public curSelectItem:EndLessItemUI;

    // private img_right:eui.Image;
    // private img_left:eui.Image;
    constructor()
    {
        super('EndLessSelectWeaponView')
    }

    public init()
    {
        let list = [18,16,7,17,14];
        let arr = [];
        for(let v of list)
        {
            let data = {
                id:v,
                index:list.indexOf(v) + 1
            }
            arr.push(data);
        }
        this.selectList.itemRenderer = EndLessItemUI;
        this._listDataArr = new eui.ArrayCollection(arr);
        this.selectList.dataProvider = this._listDataArr;
    }

    public LREffect(obj, dir)
    {
         var onComplete1:Function = function(){
            if(obj != null){
                var onComplete2:Function = function(){
                    egret.Tween.get(obj).to({
                     alpha:0.5,
                     x:obj.x - dir * 20
                },500).call(onComplete1,this);  
                }
                egret.Tween.get(obj).to({
                    alpha:1,
                    x:obj.x + dir * 20
                }, 500).call(onComplete2, this);
            }
        };
        onComplete1();
    }

    public changeSelect(e:BaseEvent)
    {
        let parma = e.param;
        let index = parma['index'];

        if(index != null)
        {
            if(this.curSelectItem)
            {
                this.curSelectItem.cancelSelectState();
            }
            let item:EndLessItemUI = this.selectList.getChildAt(index) as EndLessItemUI;
            if(item)
            {
                item.setSelectState();
                this.curSelectItem = item;
            }
        }
    }

    public addEvent()
    {
        GameUtil.addEventListener(EventConst.ENDLESS_CHANGE_WEAPON, this.changeSelect, this);
    }

    public changeListType()
    {
        if (!this.isShow) {
            egret.Tween.get(this.weapon_group).to({x:0}, 300, egret.Ease.sineOut);
            this.isShow = true;
        } else {
            egret.Tween.get(this.weapon_group).to({x:this.posScrollerClose}, 300, egret.Ease.sineIn);
            this.isShow = false;
        }
    }

    public removeEvent()
    {
        // this.btn_weapon.removeTapHandler();
        GameUtil.removeEventListener(EventConst.ENDLESS_CHANGE_WEAPON, this.changeSelect, this);
    }

    public clear()
    {
        super.clear();
        // EffectUtil.instance().StopEffect(this.img_left);
        // EffectUtil.instance().StopEffect(this.img_right);
    }
}

window['EndLessSelectWeaponUI'] = EndLessSelectWeaponUI;